﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KC.Presentation.Mv8CMS
{
	public partial class GalleryPoker : Form
	{
		private string Filename;
		private System.IO.FileInfo fi;
		public string DisplayName, Description;
		public Image img;

		public GalleryPoker(string filename)
		{
			InitializeComponent();
			Filename = filename;
			fi = new System.IO.FileInfo(filename);
			pbThumb.ImageLocation = filename;

			// Populate stats
			DataTable dt = new DataTable();
			dt.Columns.Add(new DataColumn("Property", typeof(string)));
			dt.Columns.Add(new DataColumn("Value", typeof(string)));

			DataRow dr = dt.NewRow();
			dr[0] = "Filename";
			dr[1] = System.IO.Path.GetFileNameWithoutExtension(filename);
			dt.Rows.Add(dr);
			
			// File size
			dr = dt.NewRow();
			dr[0] = "Size";
			dr[1] = (fi.Length / (1024 * 1024)).ToString("###,###,###") + " MB";
			dt.Rows.Add(dr);

			// Dimensions
			try { img = Image.FromFile(filename); }
			catch (OutOfMemoryException) { } // Guess you don't get a thumbnail in your Poker
			if (img != null) {
				dr = dt.NewRow();
				dr[0] = "Dimensions";
				dr[1] = img.Width.ToString("###,###,###") + " x " + img.Height.ToString("###,###,###");
				dt.Rows.Add(dr);

				// Image format
				dr = dt.NewRow();
				dr[0] = "Format";
				dr[1] = img.RawFormat.ToString();
				dt.Rows.Add(dr); }

			gvStats.DataSource = dt;
		}

		private void GalleryPoker_Load(object sender, EventArgs e)
		{

		}

		private void btnCxl_Click(object sender, EventArgs e)
		{
			DisplayName = "";
			Description = "";
			DialogResult = System.Windows.Forms.DialogResult.Cancel;
			Close();
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			DisplayName = txtDisplayName.Text;
			Description = txtDescription.Text;
			DialogResult = System.Windows.Forms.DialogResult.OK;
			Close();
		}
	}
}
